
// const BASE_URL = 'http://localhost:8081';
// const BASE_URL = 'http://localhost';

let ajaxTimes=0;

export const myRequest = (options) => {
	
	let header = {...options.header};
	
	if(options.url != '/login' || options.url !="/api/student/user/register"){
		header['Authorization'] = uni.getStorageSync("token");
	}
	
	ajaxTimes++;
	
	uni.showLoading({
		title: '加载中',
		mask: true
	})
	return new Promise((resolve,reject)=>{
		
		
		uni.request({
			// url: BASE_URL + options.url,
			url: options.url,
			method: options.method || 'GET',
			data: options.data || {},
			header,
			success: (res) => {
				resolve(res)
			},
			fail: (err) => {
				uni.showToast({
					title: "请求有误"
				})
				reject(err);
			},
			// 完成之后关闭加载效果
			complete:()=>{
				ajaxTimes--;
				if(ajaxTimes===0){
					//  关闭正在等待的图标
					uni.hideLoading();
				}
			}
		})
	})
}